﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using DTO;
using BLL;
using DAL;

namespace Children
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class DangNhap : Window
    {
        public DangNhap()
        {
            InitializeComponent();
        }

        private void move(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }

        private void btn_Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void bnt_Minimize_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        // SQLCommand
        SqlCommand cmd;
        //DataSet dùng để lưu trữ lại dữ liệu lấy từ SQL Server
        SqlDataReader reader;
        SqlConnection conn = sqlConnectionData.HamKetNoi();


        private void btn_DangNhap_Click(object sender, RoutedEventArgs e)
        {


            try
            {

                string command = @"SELECT *FROM NhanVien WHERE MaNV = '" + txt_User.Text + "' AND MatKhau = '" + pwb_MatKhau.Password + "'";
                cmd = new SqlCommand(command, conn);

                conn.Open();
                reader = cmd.ExecuteReader();

                int count = 0;
                while (reader.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    this.Visibility = Visibility.Hidden;
                    form1 form = new form1();
                    form.ShowDialog();
                    this.Visibility = Visibility.Visible;
                }
                else if (count > 1)
                    MessageBox.Show("Duplicate Username and Password... Access denied");
                else
                    MessageBox.Show("Username and Password is Not correct... Please try again...", "NOT CORRECT");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }
    }
}

       


     

       
   